/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package databook.util;

import java.util.Comparator;

import prefuse.data.util.Sort;
import prefuse.data.Tuple;
/**
 *
 * @author zach
 */
public class DatabookSort extends Sort {
    
    public Comparator getComparator() {
        return new NodeComparator();
        
    }
    
    class NodeComparator implements Comparator {
        
        public int compare(Object o1, Object o2) {
            String id1 = ((Tuple)o1).getString("ID");
            String id2 = ((Tuple)o2).getString("ID");
            String c1 = id1;
            String c2 = id2;
            if (MajorMap.isMajor(id1)) {
                if (MajorMap.getCollege(id1).equals(MajorMap.getCollege(id2))) {
                    if (!MajorMap.getDepartment(id1).equals(MajorMap.getDepartment(id2))) {
                        c1 = MajorMap.getDepartment(id1);
                        c2 = MajorMap.getDepartment(id2);
                    }
                } else {
                    c1 = MajorMap.getCollege(id1);
                    c2 = MajorMap.getCollege(id2);
                }
            } else if (MajorMap.isDept(id1)) {
                if (!MajorMap.getCollegeFromDept(id1).equals(MajorMap.getCollegeFromDept(id2))) {
                    c1 = MajorMap.getCollegeFromDept(id1);
                    c2 = MajorMap.getCollegeFromDept(id2);
                }
            }
            return c1.compareTo(c2);
        }
    }
}


